<?php
/**
 * JobHelper.php class file.
 * @author wudg <544038230@qq.com>
 * @date 2020/12/31- 下午12:15
 */

namespace common\helpers;


use common\jobs\copy\CopyGoodsToCloud;
use common\jobs\copy\CopyGoodsToPdd;
use common\jobs\copy\CopyGoodsToSpider;
use common\drivers\queue\Manager;
use common\jobs\Factory;
use Yii;
class JobHelper
{
    /**
     * 投递到采集队列
     * @param array $args
     */
    public static function toSpider(array $args)
    {
        $spider = new CopyGoodsToSpider($args);
        Manager::factory(Yii::$app->params['queue']['crawler'].'_'.($args['mall_id']%2))->push($spider);
    }


    /**
     * 推送到弹性采集队列
     * @param array $args
     * @throws \Littlesqx\AintQueue\Exception\InvalidDriverException
     * @throws \Throwable
     */
    public static function toAintSpider(array $args)
    {
        $job = new \common\jobs\copy\CopyGoodsToSpider($args);
        $queue = Factory::make(Yii::$app->params['aint-queue']['spider_channel']);
        $queue->push($job);
    }


    /**
     * 推送至弹性入云库队列
     * @param array $args
     * @throws \Littlesqx\AintQueue\Exception\InvalidDriverException
     * @throws \Throwable
     */
    public static function toAintCloud(array $args)
    {
        $job = new \common\jobs\copy\CopyGoodsToCloud($args);

        $queue = Factory::make(Yii::$app->params['aint-queue']['cloud_channel']);
        $queue->push($job);
    }


    /**
     * 推送至弹性上货队列
     * @param array $args
     * @throws \Littlesqx\AintQueue\Exception\InvalidDriverException
     * @throws \Throwable
     */
    public static function toAintCopy(array $args)
    {
        $job = new \common\jobs\copy\CopyGoodsToPdd($args);

        $queue = Factory::make(Yii::$app->params['aint-queue']['copy_channel']);
        $queue->push($job);
    }





    /**
     * 投递到写入云数据库
     * @param array $args
     */
    public static function toCloud(array $args)
    {
        $cloud = new CopyGoodsToCloud($args);
        if($args['mall_id'] == '219891145'){
            Manager::factory(Yii::$app->params['queue']['cloud'].'_4')->push($cloud);
        }else{
            Manager::factory(Yii::$app->params['queue']['cloud'].'_'.($args['mall_id']%2))->push($cloud);
        }

    }


    /**
     * 投递到上货业务
     * @param array $args
     */
    public static function toCopy(array $args)
    {
        $copy = new CopyGoodsToPdd($args);
        if($args['mall_id'] == '857919756'){
            Manager::factory(Yii::$app->params['queue']['copy'].'_4')->push($copy);
        }else{
            Manager::factory(Yii::$app->params['queue']['copy'].'_'.($args['mall_id']%2))->push($copy);
        }

    }

    /**
     * 投递到上货重复分析任务
     * @param array $args
     */
    public static function toCopyrefound(array $args)
    {
        $copy = new CopyGoodsToPdd($args);
        if($args['mall_id'] == '857919756'){
            Manager::factory(Yii::$app->params['queue']['copyrefound'].'_4')->push($copy);
        }else{
            Manager::factory(Yii::$app->params['queue']['copyrefound'].'_'.($args['mall_id']%2))->push($copy);
        }

    }

    /**
     * 投递到上货云库重复分析任务
     * @param array $args
     */
    public static function toCloudrefound(array $args)
    {
        $copy = new CopyGoodsToPdd($args);
        if($args['mall_id'] == '219891145'){
            Manager::factory(Yii::$app->params['queue']['cloudrefound'].'_4')->push($copy);
        }else{
            Manager::factory(Yii::$app->params['queue']['cloudrefound'].'_'.($args['mall_id']%2))->push($copy);
        }

    }



}